﻿using System;
using System.Drawing;
using System.IO;
using log4net;
using log4net.Config;
using FLMScan.Parameters;

namespace FLMScan.Tools
{
    class LoggingHelper
    {
        public static void MakeLogger()
        {
            string fullExecutablePath = typeof(FLMScanInstance).Assembly.Location;
            string executablePath = Path.GetDirectoryName(fullExecutablePath);

            FLMScanParameters parameters = new FLMScanParameters(executablePath);

            ILog logger = InitializeLogger(executablePath, parameters);
        }

        public static void Log(Rectangle rect, ILog logger, String prefix)
        {
            logger.DebugFormat("{0} Rectangle: width:{1} height:{2}", prefix, rect.Width, rect.Height);
        }

        private static ILog InitializeLogger(string executablePath, FLMScanParameters parameters)
        {
            ILog logger = LogManager.GetLogger(typeof(LoggingHelper));
            string logConfigFilePath = executablePath + @"\Config\" + parameters.LogConfig;

            if (File.Exists(logConfigFilePath))
            {
                XmlConfigurator.Configure(new FileInfo(logConfigFilePath));
            }

            return logger;
        }
    }
}
